"use strict"
var rp = require('request-promise');
var weiboSdk = require('nodeweibo');
var moment = require('moment');
weiboSdk.init(require('./setting.json'));
exports = module.exports = class Weibo {
    constructor(token) {
        this.uid = token.uid;
        this.access_token = token.access_token;
        this.token = token;
        this.sdk = weiboSdk;
        this.sdk.Users.show({ 'uid': this.uid, access_token: this.access_token }, (data) => {
            this.userInfo = data;
        });
    }

    uploadStatuses(statuses) {
        statuses.access_token = this.access_token;
        if (statuses.pic) {
            this.sdk.Statuses.upload(statuses, function(ret) {
                console.log(ret);
            });
        }
        else{
            this.sdk.Statuses.update(statuses, function(ret) {
                console.log(ret);
            });
        }

    }
    uploadImgStatuses(statuses) {
        statuses.access_token = this.access_token;
        this.sdk.Statuses.upload_url_text(statuses, (ret) => {
            console.log(ret);
        });
    }
    getExpireAt(format) {
        format = format || 'YYYY-MM-DD';
        return moment(this.token.expireAt).format(format);
    }
    getToken() {
        return this.token;
    }
    getNickName() {
        return this.getUserInfo().screen_name;
    }
    getProfileImgUrl() {
        return this.getUserInfo().profile_image_url;
    }
    getUrl() {
        return this.getUserInfo().url;
    }
    getUserInfo() {
        return this.userInfo || {};
    }
    getUid() {
        return this.uid;
    }

}
